package com.ruoyi.accountant.domain.other;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/****
 * 表示12个月的报告信息
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProfitLossReportRow {
    private List<ProfitLossReport> data; // 每个具体原因的12个月报告
    private BigDecimal count;
    private List<ProfitLossReport> parentData = new ArrayList<>(); //所有具体原因的12个月报告
    private BigDecimal parentCount; // 父原因总额

    public ProfitLossReportRow(List<ProfitLossReport> data, BigDecimal count) {
        this.data = data;
        this.count = count;
    }

    /***
     * 计算总额
     * @return
     */
    public BigDecimal getParentCount() {
        BigDecimal bigDecimal = new BigDecimal(0);
        for (ProfitLossReport parentDatum : parentData) {
            bigDecimal = bigDecimal.add(parentDatum.getMoney());
        }
        return bigDecimal;
    }

    public BigDecimal getDataByMonth(int j) {
        for (ProfitLossReport datum : data) {
            if(datum.getMonth() == j) {
                return datum.getMoney();
            }
        }
        return new BigDecimal(0);
    }

    public BigDecimal getTaxByMonth(int x) {
        if(data != null) {
            for (ProfitLossReport datum : data) {
                if(datum.getMonth() == x) {
                    return datum.getTax();
                }
            }
        }
        return new BigDecimal(0);
    }
}
